import 'package:erp/Entity/PurchaseOrder.dart';
import 'package:erp/Store/PurchaseStore.dart';
import 'package:erp/UI/CodeResources/Localization.dart';
import 'package:erp/UI/Components/EventfulState.dart';
import 'package:erp/UI/Components/ListDividerGenerator.dart';
import 'package:erp/UI/Components/LogoScaffold.dart';
import 'package:erp/UI/Pages/PurchasePages/PurchaseOrderDetailPage.dart';
import 'package:erp/UI/Pages/PurchasePages/PurchasePage.dart';
import 'package:erp/UI/Routes.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class PurchaseOrderPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var currentLocale = AppLocalizations.of(context);

    return Directionality(
      textDirection: currentLocale.textDirection,
      child: PurchaseOrderPageStateful(),
    );
  }
}

class PurchaseOrderPageStateful extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => PurchasePageState();
}

class PurchasePageState extends EventfulState<PurchaseOrderPageStateful> {
//  final primaryColor = Color.fromARGB(0xff, 0xe5, 0x73, 0x73); //#e57373
  final listLabelTextStyle = TextStyle(fontSize: 14.0);
  final avatarRadius = 64.0;

  @override
  void initState() {
    eventIds = [

    ];
    super.initState();
  }



  @override
  Widget build(BuildContext context) {
    var dividerGenerator = ListDividerGenerator(PurchaseStore.purchaseOrders.map((item) => buildWidget(context, item)).toList(), Divider());
    return LogoScaffold(
      heroName: "PurchaseHero",
        assetsLogoName: "assets/pictures/import.png",
        title: "مال ئەكىرىش بىتى",
        contentDelegate: SliverChildListDelegate(dividerGenerator.items),
        floatingActionButton: Hero(
          tag: "PurchasePageLogoHero",
          child: FloatingActionButton(
//            backgroundColor: primaryColor,
              child: Icon(Icons.add),
              onPressed: () {
                Navigator.of(context).push(MaterialPageRoute(builder: (context) => PurchasePage()));
              }),
        ),
        useSearchBar: true,


    );
  }

  Widget buildWidget(BuildContext context, PurchaseOrder order) => ExpansionTile(
        leading: Hero(
            tag: order.orderNumber,
            child: Image.asset(
              "assets/pictures/list.png",
              height: 48.0,
              width: 48.0,
            )
        ),
        title: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
//                Icon(Icons.people, color: primaryColor),
                Expanded(child: Text("تەمىنلىگۈچى: ", style: listLabelTextStyle,), ),
                Expanded(child: Text(order.supplierName, style: listLabelTextStyle, textAlign: TextAlign.end), flex: 2,),
              ],
            ),
            Row(
              children: <Widget>[
//                Icon(Icons.access_time, color: primaryColor),
                Expanded(child: Text("ۋاقتى: ", style: listLabelTextStyle)),
                Expanded(child: Text(DateFormat("yyyy-MM-dd HH:mm:ss").format(order.time), style: listLabelTextStyle, textAlign: TextAlign.end), flex: 2,),
              ],
            ),
            Row(
              children: <Widget>[
//                Icon(Icons.attach_money, color: primaryColor),
                Expanded(child: Text("سوممىسى: ", style: listLabelTextStyle)),
                Expanded(child: Text(order.amount.toString(), style: listLabelTextStyle, textAlign: TextAlign.end,), flex: 2,),
              ],
            ),
          ],
        ),
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(top: 0.0, bottom: 10.0, right: 56.0, left: 56.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    Icon(
                        Icons.person,
                        color: Theme.of(context).primaryColor
                    ),
                    Expanded(child: Text("بىجىرگۈچى: ", )),
                    Expanded(child: Text(order.employeeName, textAlign: TextAlign.end), flex: 2,),
                  ],
                ),
                Row(
                  children: <Widget>[
                    Icon(
                      Icons.confirmation_number,
                        color: Theme.of(context).primaryColor
                    ),
                    Expanded(child: Text("تالون نومۇرى: ")),
                    Expanded(child: Text(order.orderNumber, textAlign: TextAlign.end), flex: 2,),
                  ],
                ),
                Padding(
                  padding: EdgeInsets.symmetric(vertical: 5.0),
                  child: FlatButton(onPressed: (){
                    Navigator.push(context, MaterialPageRoute(builder: (context)=> PurchaseOrderDetailPage(order.orderNumber.toString(), order)));
                  }, child: Text("بۇ يەرنى چىكىپ تەپسىلاتىنى كۆرۈڭ"),)
                ),
              ],
            ),
          )
        ],
    trailing: null,
//    backgroundColor: primaryColor.withAlpha(10),
  );

}




















